package reusingclass;


public class Exercise5 {
	public static void main(String[] args) {
/* 1. load class A, initialize static members in class A
 * 2. load class C, initialize static members in class C
 * 3. create an object of class A, initialize instance members in class A, 
 * 		then call its constructor
 * 4. create an object of class C, initialize instance members in class C, in this case,
 * 			load class B, initialze the static members, and then the instance members in
 * 			class B, then call its contructor to create an Object of B.
 * 		then call C's constructor
 *  
*/		
		C c = new C();
	}
}

class A {
	private static int i = 11;
	static {
		System.out.println(i);
	}
	private int j = 22;
	{
		System.out.println(j);
	}
	
	A() {
		int k = 33;
		System.out.println("A Constructor" + k);
	}
}

class B {
	private static int counter = 0;
	private static float f1 = 1.1f;
	static {
		System.out.println(f1);
	}
	private float f2 = 2.2f;
	{
		System.out.println(f2);
	}
	private int id = counter++;
	B() {
		float f3 = 3.3f;
		System.out.println("B Constructor for object " + id + " " + f3);
	}
}

class C extends A {
//	static member initialized when loading this class
//	private static B b = new B(); 
/*如果定义时赋值，就会在编译期创建一个B的对象，执行优先于下一个static语句
 *执行结果为：
 *****************
  11
	1.1
	2.2
	B Constructor for object 0 3.3
	hello
	22
	A Constructor33
	world
	2.2
	B Constructor for object 1 3.3
 *****************
*/
		private static B b;
	private static String s1 = "hello";
	static {
		System.out.println(s1);
	}
	private String s2 = "world";
	{
		System.out.println(s2);
	}
//	instance member initialized when creating an object of this class
	private B b1 = new B();
}
/*output:
 ***************
 	11
	hello
	22
	A Constructor33
	world
	1.1
	2.2
	B Constructor for object 0 3.3
 *************** 
 */
